import fs from 'fs'

function readJson(dir){
    return new Promise((resolve,reject)=>{
        fs.readFile(dir,'utf8',(err,data)=>{
            err && reject(err)
            data = JSON.parse(data)
            resolve(data)
        })
    }).catch(err=>{
        console.log(err)
    })
}

function writeJSON(dir,content){
    return new Promise((resolve,reject)=>{
        fs.writeFile(dir,content,'utf8',(err)=>{
            err && reject(err)
            resolve('success')
        })
    }).catch(err=>{
        console.log(err)
    })  
}

const PromiseJson = {readJson,writeJSON}

export default PromiseJson
export {readJson,writeJSON}